package ControllerDelete

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"test/ControllerConnct"
	"test/middleware"
	"test/models"
	"test/utils"
)

func Delete() {

	db := ControllerConnct.Connection()
	var studentid string
	var students models.STUDENT
	//var studentname string
	//var classno string

	r := gin.Default()
	r.Use(middleware.CORSMiddleware())

	r.DELETE("/database/MB-TI", func(c *gin.Context) {

		//可删除的选项
		studentno = c.PostForm("StudentId")
		//studentname = c.PostForm("student_name")
		//classno = c.PostForm("class_no")

		//var class models.Class
		//var college models.College
		//var test models.TestMS
		//var dept models.Dept

		//?????????
		err := c.ShouldBindJSON(&students)
		if err != nil {
			fmt.Println(err.Error())
		}
		db.Where("StudentId = ?", studentid).Delete(&students)
		//db.Where("student_name = ?", studentname).Delete(&students)
		c.JSON(http.StatusOK, utils.Result{
			Code:    utils.SUCCESS,
			Message: "删除成功",
		})
	})
	//执行查询查找数据是否已经删除
	//Select()
	err := r.Run(":8099")
	if err != nil {
		return
	}
}
